#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string>
#include <iostream>
#include <unistd.h>

using namespace std;

// 进程A 向管道当中写 “i am process A”
int main()
{
    int n = mkfifo("./testfifo", 0664);
    if (n == -1)
    {
        perror("mkfifo");
    }

    // int fd = open("./tsetfifo", O_WRONLY);
    int fd = open("./testfifo", O_WRONLY);
    if (fd < 0)
    {
        perror("open");
        return 1;
    }

    // cout << "ProcessB open file done" << endl;

    string str = "i am process A";

    write(fd, str.c_str(), str.size());

    int m = unlink("./testfifo");
    if (m == -1)
    {
        perror("unlink");
    }
    close(fd);
    return 0;
}
